package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.IApArticleConfigService;
import com.heima.model.common.enums.WmNewsMessageConstants;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class ArticleDownOrUpListener {
    @Autowired
    private IApArticleConfigService apArticleConfigService;
    //订阅主题,接收消息
    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage (String message){
        if (StringUtils.isNotBlank(message)){
            //解析消息
            Map map = JSON.parseObject(message, Map.class);
            //调用方法修改文章配置表的isDown状态
            apArticleConfigService.downOrUp(map);
        }
    }
}
